<!DOCTYPE html>
<html>
<!-- Created by GNU Texinfo 7.1.1, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- This file documents the use of the GNU compilers.

Copyright © 1988-2023 Free Software Foundation, Inc.

Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "Funding Free Software", the Front-Cover
Texts being (a) (see below), and with the Back-Cover Texts being (b)
(see below).  A copy of the license is included in the section entitled
"GNU Free Documentation License".

(a) The FSF's Front-Cover Text is:

A GNU Manual

(b) The FSF's Back-Cover Text is:

You have freedom to copy and modify this GNU Manual, like GNU
     software.  Copies published by the Free Software Foundation raise
     funds for GNU development. -->
<title>C++ Interface (Using the GNU Compiler Collection (GCC))</title>

<meta name="description" content="C++ Interface (Using the GNU Compiler Collection (GCC))">
<meta name="keywords" content="C++ Interface (Using the GNU Compiler Collection (GCC))">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta name="viewport" content="width=device-width,initial-scale=1">

<link href="index.html" rel="start" title="Top">
<link href="Indices.html" rel="index" title="Indices">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="C_002b_002b-Extensions.html" rel="up" title="C++ Extensions">
<link href="Template-Instantiation.html" rel="next" title="Template Instantiation">
<link href="Vague-Linkage.html" rel="prev" title="Vague Linkage">
<style type="text/css">
<!--
a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em}
kbd.key {font-style: normal}
span:hover a.copiable-link {visibility: visible}
-->
</style>


</head>

<body lang="en_US">
<div class="section-level-extent" id="C_002b_002b-Interface">
<div class="nav-panel">
<p>
Next: <a href="Template-Instantiation.html" accesskey="n" rel="next">Where&rsquo;s the Template?</a>, Previous: <a href="Vague-Linkage.html" accesskey="p" rel="prev">Vague Linkage</a>, Up: <a href="C_002b_002b-Extensions.html" accesskey="u" rel="up">Extensions to the C++ Language</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Indices.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<h3 class="section" id="C_002b_002b-Interface-and-Implementation-Pragmas"><span>7.4 C++ Interface and Implementation Pragmas<a class="copiable-link" href="#C_002b_002b-Interface-and-Implementation-Pragmas"> &para;</a></span></h3>

<a class="index-entry-id" id="index-interface-and-implementation-headers_002c-C_002b_002b"></a>
<a class="index-entry-id" id="index-C_002b_002b-interface-and-implementation-headers"></a>
<a class="index-entry-id" id="index-pragmas_002c-interface-and-implementation"></a>

<p><code class="code">#pragma interface</code> and <code class="code">#pragma implementation</code> provide the
user with a way of explicitly directing the compiler to emit entities
with vague linkage (and debugging information) in a particular
translation unit.
</p>
<p><em class="emph">Note:</em> These <code class="code">#pragma</code>s have been superceded as of GCC 2.7.2
by COMDAT support and the &ldquo;key method&rdquo; heuristic
mentioned in <a class="ref" href="Vague-Linkage.html">Vague Linkage</a>.  Using them can actually cause your
program to grow due to unnecessary out-of-line copies of inline
functions.
</p>
<dl class="table">
<dt><a id="index-_0023pragma-interface"></a><span><code class="code">#pragma interface</code><a class="copiable-link" href="#index-_0023pragma-interface"> &para;</a></span></dt>
<dt><code class="code">#pragma interface &quot;<var class="var">subdir</var>/<var class="var">objects</var>.h&quot;</code></dt>
<dd><p>Use this directive in <em class="emph">header files</em> that define object classes, to save
space in most of the object files that use those classes.  Normally,
local copies of certain information (backup copies of inline member
functions, debugging information, and the internal tables that implement
virtual functions) must be kept in each object file that includes class
definitions.  You can use this pragma to avoid such duplication.  When a
header file containing &lsquo;<samp class="samp">#pragma interface</samp>&rsquo; is included in a
compilation, this auxiliary information is not generated (unless
the main input source file itself uses &lsquo;<samp class="samp">#pragma implementation</samp>&rsquo;).
Instead, the object files contain references to be resolved at link
time.
</p>
<p>The second form of this directive is useful for the case where you have
multiple headers with the same name in different directories.  If you
use this form, you must specify the same string to &lsquo;<samp class="samp">#pragma
implementation</samp>&rsquo;.
</p>
</dd>
<dt><a id="index-_0023pragma-implementation"></a><span><code class="code">#pragma implementation</code><a class="copiable-link" href="#index-_0023pragma-implementation"> &para;</a></span></dt>
<dt><code class="code">#pragma implementation &quot;<var class="var">objects</var>.h&quot;</code></dt>
<dd><p>Use this pragma in a <em class="emph">main input file</em>, when you want full output from
included header files to be generated (and made globally visible).  The
included header file, in turn, should use &lsquo;<samp class="samp">#pragma interface</samp>&rsquo;.
Backup copies of inline member functions, debugging information, and the
internal tables used to implement virtual functions are all generated in
implementation files.
</p>
<a class="index-entry-id" id="index-implied-_0023pragma-implementation"></a>
<a class="index-entry-id" id="index-_0023pragma-implementation_002c-implied"></a>
<a class="index-entry-id" id="index-naming-convention_002c-implementation-headers"></a>
<p>If you use &lsquo;<samp class="samp">#pragma implementation</samp>&rsquo; with no argument, it applies to
an include file with the same basename<a class="footnote" id="DOCF8" href="#FOOT8"><sup>8</sup></a> as your source
file.  For example, in <samp class="file">allclass.cc</samp>, giving just
&lsquo;<samp class="samp">#pragma implementation</samp>&rsquo;
by itself is equivalent to &lsquo;<samp class="samp">#pragma implementation &quot;allclass.h&quot;</samp>&rsquo;.
</p>
<p>Use the string argument if you want a single implementation file to
include code from multiple header files.  (You must also use
&lsquo;<samp class="samp">#include</samp>&rsquo; to include the header file; &lsquo;<samp class="samp">#pragma
implementation</samp>&rsquo; only specifies how to use the file&mdash;it doesn&rsquo;t actually
include it.)
</p>
<p>There is no way to split up the contents of a single header file into
multiple implementation files.
</p></dd>
</dl>

<a class="index-entry-id" id="index-inlining-and-C_002b_002b-pragmas"></a>
<a class="index-entry-id" id="index-C_002b_002b-pragmas_002c-effect-on-inlining"></a>
<a class="index-entry-id" id="index-pragmas-in-C_002b_002b_002c-effect-on-inlining"></a>
<p>&lsquo;<samp class="samp">#pragma implementation</samp>&rsquo; and &lsquo;<samp class="samp">#pragma interface</samp>&rsquo; also have an
effect on function inlining.
</p>
<p>If you define a class in a header file marked with &lsquo;<samp class="samp">#pragma
interface</samp>&rsquo;, the effect on an inline function defined in that class is
similar to an explicit <code class="code">extern</code> declaration&mdash;the compiler emits
no code at all to define an independent version of the function.  Its
definition is used only for inlining with its callers.
</p>
<a class="index-entry-id" id="index-fno_002dimplement_002dinlines-1"></a>
<p>Conversely, when you include the same header file in a main source file
that declares it as &lsquo;<samp class="samp">#pragma implementation</samp>&rsquo;, the compiler emits
code for the function itself; this defines a version of the function
that can be found via pointers (or by callers compiled without
inlining).  If all calls to the function can be inlined, you can avoid
emitting the function by compiling with <samp class="option">-fno-implement-inlines</samp>.
If any calls are not inlined, you will get linker errors.
</p>
</div>
<div class="footnotes-segment">
<hr>
<h4 class="footnotes-heading">Footnotes</h4>

<h5 class="footnote-body-heading"><a id="FOOT8" href="#DOCF8">(8)</a></h5>
<p>A file&rsquo;s <em class="dfn">basename</em>
is the name stripped of all leading path information and of trailing
suffixes, such as &lsquo;<samp class="samp">.h</samp>&rsquo; or &lsquo;<samp class="samp">.C</samp>&rsquo; or &lsquo;<samp class="samp">.cc</samp>&rsquo;.</p>
</div>
<hr>
<div class="nav-panel">
<p>
Next: <a href="Template-Instantiation.html">Where&rsquo;s the Template?</a>, Previous: <a href="Vague-Linkage.html">Vague Linkage</a>, Up: <a href="C_002b_002b-Extensions.html">Extensions to the C++ Language</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Indices.html" title="Index" rel="index">Index</a>]</p>
</div>



</body>
</html>
